# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=libvoikko
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.3
pkgrel=1
pkgdesc="A spelling and grammar checker, hyphenator and collection of related linguistic data for Finnish language (mingw-w64)"
arch=('any')
url="http://voikko.sourceforge.net"
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3")
source=("https://www.puimula.org/voikko-sources/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('e843df002fcea2a90609d87e4d6c28f8a0e23332d3b42979ab1793e18f839307')

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  # Workaround encoding error
  export LANG=en_US.UTF-8
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --enable-hfst=false \
    --with-dictionary-path=${MINGW_PREFIX}/share/voikko

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  local _py3ver=$(${MINGW_PREFIX}/bin/python3 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")

  mkdir -p "${pkgdir}${MINGW_PREFIX}/lib/python${_py3ver}/site-packages"
  cp "${srcdir}/${_realname}-${pkgver}/python/libvoikko.py" "${pkgdir}${MINGW_PREFIX}"/lib/python${_py3ver}/site-packages/libvoikko.py
}
